<style>
a {
	color:#000000;
    font-size:12px;
	text-decoration: none;
}
</style>
<script type="text/javascript">

	$(function() {
		$('#resource_treegrid').treegrid({
			url : '${request.contextPath}${namespace?default('')}/mp/sysres/resource-datagrid.json',
			idField : 'id',
			treeField : 'text',
			parentField : 'pId',
			fit : true,
			nowrap:false,
			fitColumns : true,
			border : false,
			frozenColumns : [ [{
				title : 'bianhao',
				field : 'id',
				width : 150,
				hidden : true
			},{
				field : 'text',
				title : '${action.getDatagridTitle('name')}',
				width : 200
			} ] ],
			columns : [ [ {
				field : 'keyType',
				title : '${action.getDatagridTitle('keyType')}',
				width : 100,
				formatter : function(value, row, index) {
					return row.attributes.keyType;
				}
			}, {
				field : 'ordinal',
				title : '${action.getDatagridTitle('ordinal')}',
				width : 50,
				formatter : function(value, row, index) {
					return row.attributes.ordinal;
				}
			}, {
				field : 'keyCode',
				title : '${action.getDatagridTitle('keyCode')}',
				width : 50,
				formatter : function(value, row, index) {
					return row.attributes.keyCode;
				}
			},{
				field : 'keyValue',
				title : '${action.getDatagridTitle('keyValue')}',
				width : 120,
				formatter : function(value, row, index) {
					return row.attributes.keyValue;
				}
			},{
				field : 'cascading',
				title : '${action.getDatagridTitle('cascading')}',
				width : 60,
				formatter : function(value, row, index) {
					return row.attributes.cascading;
				}
			},{
				field : 'comments',
				title : '${action.getDatagridTitle('comments')}',
				width : 150,
				formatter : function(value, row, index) {
					return row.attributes.comments;
				}
			}, {
				field : 'PId',
				title : '上级菜单ID',
				width : 150,
				hidden : true
			},{
				field : 'hasLeaf',
				title : '是否子叶',
				hidden : true,
				formatter : function(value, row, index) {
					return row.attributes.hasLeaf;
				}
			},{
				field : 'action',
				title : '${action.getProperty('net.esj.background.message','bg.datagrid.action')}',
				width : 50,
				formatter : function(value, row, index) {
					var reval = '';
					reval +='<a onclick="resource_edit(\''+row.id+'\',\''+row.PId+'\');" href="javascript:;; ">${action.getProperty('net.esj.background.message','bg.datagrid.edit')}</a>&nbsp;';
					reval +='<a onclick="resource_delete(\''+row.id+'\');" href="javascript:;;" >${action.getProperty('net.esj.background.message','bg.datagrid.delete')}</a>';
					return reval;
				}
			} ] ],
			toolbar : [ {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.add')}',
				iconCls : 'icon-add',
				handler : function() {
					resource_add();
				}
			}, '-', {
				text : '${action.getText('list.button.expandAll')}',
				iconCls : 'icon-redo',
				handler : function() {
					$('#resource_treegrid').treegrid('expandAll');
				}
			}, '-', {
				text : '${action.getText('list.button.collapseAll')}',
				iconCls : 'icon-undo',
				handler : function() {
					$('#resource_treegrid').treegrid('collapseAll');
				}
			}, '-', {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.refresh')}',
				iconCls : 'icon-reload',
				handler : function() {
					$('#resource_treegrid').treegrid('reload');
				}
			} ]
		});
	});

	function resource_add() {
		var node = $('#resource_treegrid').treegrid('getSelected');
		var pId = '';
		if(node){
			pId = node.id;
			if(!node.attributes.hasLeaf){
				$.messager.alert("","该节点下不允许再添加节点","info");
				return; 
			}
		}
		$('<div/>').dialog({
			href : '${request.contextPath}${namespace?default('')}/mp/sysres/resource-form.htm?pId='+pId+'&n='+Math.random(),
			width : 600,
			height : 400,
			modal : true,
			title : '${action.getText('form.add.title')}',
			buttons : [ {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.add')}',
				iconCls : 'icon-add',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#resource_form').form('submit', {
						url : '${request.contextPath}${namespace?default('')}/mp/sysres/resource-add.json',
						onSubmit: function(){
							return $(this).form('validate');
        				},
						success : function(json) {
							eval("json="+json);
							if(json.level!='error'){
								$.messager.alert(json.title,json.msg,json.level);
								d.dialog('destroy');
								$("#resource_treegrid").treegrid('reload');
							}else{
								$.messager.alert(json.title,json.msg,json.level);
							}
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
	}
	function resource_edit(id,pId) {
		if(!pId || pId=='null'){
			pId='';
		}
		$('<div>').dialog({
			href : '${request.contextPath}${namespace?default('')}/mp/sysres/resource-form.htm?pId='+pId+'&n='+Math.random(),
			width : 600,
			height : 400,
			modal : true,
			title : '${action.getText('form.edit.title')}',
			buttons : [ {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.edit')}',
				iconCls : 'icon-edit',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#resource_form').form('submit', {
						url : '${request.contextPath}${namespace?default('')}/mp/sysres/resource-update.json',
						onSubmit: function(){
							return $(this).form('validate');
        				},
						success : function(json) {
							eval("json="+json);
							$.messager.alert(json.title,json.msg,json.level);
							d.dialog('destroy');
							$("#resource_treegrid").treegrid('reload');
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			},
			onLoad : function() {
				$('#resource_form').form('load', '${request.contextPath}${namespace?default('')}/mp/sysres/resource-load.json?id='+id+'&n='+Math.random());
			}
		});
	}
	
	function resource_delete(id) {
		if (id != undefined) {
			$('#resource_treegrid').treegrid('select', id);
		}
		var node = $('#resource_treegrid').treegrid('getSelected');
		if (node) {
			$.messager.confirm('${action.getProperty('net.esj.background.message','bg.message.info')}', '${action.getText('list.grid.delete.ask')}', function(b) {
				if (b) {
					$.ajax({
						url : '${request.contextPath}${namespace?default('')}/mp/sysres/resource-delete.json',
						data : {
							deletes : node.id
						},
						dataType : 'JSON',
						success : function(json) {
							$.messager.alert(json.title,json.msg,json.level);
							$("#resource_treegrid").treegrid('reload');
						}
					});
				}
			});
		}
	}
</script>
<table id="resource_treegrid"></table>
<!--div id="admin_cdgl_menu" class="easyui-menu" style="width:120px;display: none;">
	<div onclick="admin_cdgl_appendFun();" data-options="iconCls:'icon-add'">增加</div>
	<div onclick="admin_cdgl_deleteFun();" data-options="iconCls:'icon-remove'">删除</div>
	<div onclick="admin_cdgl_editFun();" data-options="iconCls:'icon-edit'">编辑</div>
</div-->